package com.funny.learning.english.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;

import com.funny.learning.english.R;

public class AnimationSample extends Activity{
	
	private ImageView imageView;
	private Button bt1;
	private Button bt2;
	private Button bt3;
	private Button bt4;
	private Button bt5;
	private Button bt6;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.sample_animation_layout);
		Animation animation6 = AnimationUtils.loadAnimation(AnimationSample.this, R.anim.g_mw_wrong);
		Animation animation1 = AnimationUtils.loadAnimation(AnimationSample.this, R.anim.g_mw_correct);
		Animation animation2 = AnimationUtils.loadAnimation(AnimationSample.this, R.anim.anim_view_fall);
//		Animation animation3 = AnimationUtils.loadAnimation(AnimationSample.this, R.anim.game1_layout_anim);
		Animation animation4 = AnimationUtils.loadAnimation(AnimationSample.this, R.anim.left_slide_in);
		Animation animation5 = AnimationUtils.loadAnimation(AnimationSample.this, R.anim.left_slide_out);
		
		imageView = (ImageView)findViewById(R.id.imageView);
		bt1 = (Button)findViewById(R.id.bt1);
		bt2 = (Button)findViewById(R.id.bt2);
		bt3 = (Button)findViewById(R.id.bt3);
		bt4 = (Button)findViewById(R.id.bt4);
		bt5 = (Button)findViewById(R.id.bt5);
		bt6 = (Button)findViewById(R.id.bt6);
		
		setAnimation(animation6, bt6);
		setAnimation(animation5, bt5);
		setAnimation(animation4, bt4);
//		setAnimation(animation3, bt3);
		setAnimation(animation1, bt2);
		setAnimation(animation1, bt1);
		
	}
	
	private void setAnimation(final Animation animation, View view){
		view.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(final View arg01) {
				imageView.startAnimation(animation);
				
				animation.setAnimationListener(new AnimationListener() {
					
					@Override
					public void onAnimationStart(Animation arg0) {
//						Toast.makeText(getBaseContext(), "Starrt Animation", 1000).show();
					}
					
					@Override
					public void onAnimationRepeat(Animation arg0) {
						
					}
					
					@Override
					public void onAnimationEnd(Animation arg0) {
//						Toast.makeText(getBaseContext(), "End Animation", 1000).show();
						int key = arg01.getId();
						switch (key) {
						case R.id.bt1:
							startActivity(new Intent(AnimationSample.this, TimHinhAnhActivity.class));
							break;
						case R.id.bt2:
							startActivity(new Intent(AnimationSample.this, ChonTuActivity.class));
							break;	
						case R.id.bt4:
							startActivity(new Intent(AnimationSample.this, LangNgheActivity.class));
							break;	
						default:
							break;
						}
					}
				});
			}
		});
	}

}
